/*
 * Copyright (c) 2005 -2008 Reliable Source, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Mozilla Public License v.1.1,
 * BSD, and Eclipse Public License v1.0 which accompanies this
 * distribution and is available at:
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 * 		http://www.opensource.org/licenses/bsd-license.php
 * 		http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * Contributors:
 *     IBM Corporation	     -  http://ibm.com
 *     	- initial API and implementation
 *
 *     patientos.org         - http://patientos.org
 *     	- domain and database persistence layer
 *
 *     Reliable Source, Inc. - http://reliablesource.org
 *     	- Symbiosys Application Framework,
 *     	- Symbiosys Application, Symbiosys Product
 *
 */
package org.reliablesource.symbiosys.platform.viewers;

import bsh.Interpreter;

import bsh.util.JConsole;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.reliablesource.client.ui.symbiosys.platform.SymbiosysApplication;

import java.awt.BorderLayout;

/**
 * 
 * SymbiosysShell.java<br>
 * Created on: Jun 27, 2008<br>
 *
 * @author <a href="mailto:dennis.park@gmail.com">Dennis Park</a>
 *
 * @category
 * @since 1.0
 */
public class SymbiosysShell {
    /**
     * @param args
     */
    public static void main(String[] args) {
        SymbiosysApplication.connect();

        try {
            System.setProperty("sun.awt.noerasebackground", "true");
        } catch (NoSuchMethodError error) {
        }

        Display display = new Display();
        Shell shell = new Shell(display,
                SWT.MODELESS | SWT.MIN | SWT.MAX | SWT.CLOSE | SWT.ON_TOP);
        shell.setLayout(new FillLayout());

        Composite _composite = new Composite(shell,
                SWT.NO_BACKGROUND | SWT.EMBEDDED);

        java.awt.Frame frame = SWT_AWT.new_Frame(_composite);
        java.awt.Panel panel = new java.awt.Panel(new BorderLayout()) {
                public void update(java.awt.Graphics g) {
                    paint(g);
                }
            };

        frame.add(panel);

        JConsole _jConsole = new JConsole();
        panel.add(_jConsole);

        Interpreter interpreter = new Interpreter(_jConsole);
        interpreter.setConsole(_jConsole);
        interpreter.setShowResults(true);
        interpreter.setOut(_jConsole.getOut());

        new Thread(interpreter).start();

        shell.open();

        while (!shell.isDisposed())

            if (!display.readAndDispatch())
                display.sleep();

        display.dispose();
    }
}
